package com.demo.controller;

import com.demo.service.FileHandleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;

/**
 * @author gy
 * @date 2023/2/10
 */
@RestController
@RequestMapping("/test")
public class FileHandleController {
    @Autowired
    private FileHandleService fileHandleService;

    @PostMapping("/uploadFile")
    public String uploadFile(@RequestPart("file") MultipartFile file,
                                @RequestParam(required = false) String absolutePath) {
        absolutePath = "D:\\20230210\\";
        return fileHandleService.uploadFiles(file, absolutePath);
    }

    @RequestMapping("/download")
    public String downLoad(HttpServletResponse response,@RequestParam(required = false) String filesUrl)
            throws UnsupportedEncodingException {
        filesUrl = "D:\\20230405\\图片（测试1）.png";
//        filesUrl = "D:\\typx_student\\typx_webtrn\\target\\war-webapp\\incoming\\report\\typxNew\\1655e13980b042ffab3e2f6d364c42ce\\4028ab9d864db42e01864eed94330002\\1676570451\\d9ae1799a8204b1d935e3496076f0893.docx";
//        http://youxun.webtrn.cn:80/incoming/report/typxNew/1655e13980b042ffab3e2f6d364c42ce/4028ab9d864db42e01864eed94330002/1676570451/d9ae1799a8204b1d935e3496076f0893.docx
//        https://img0.baidu.com/it/u=1705694933,4002952892&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=281
        return fileHandleService.downLoad(response, filesUrl);
    }

}
